package com.example.dryyzx.dao;

import com.example.dryyzx.entity.OutgoingRecord;
import org.apache.ibatis.jdbc.SQL;

public class OutgoingRecordSqlProvider {
    public String insertSelective(OutgoingRecord record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("outgoing_record");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getCustomerId() != null) {
            sql.VALUES("customer_id", "#{customerId,jdbcType=INTEGER}");
        }
        
        if (record.getCompanion() != null) {
            sql.VALUES("companion", "#{companion,jdbcType=VARCHAR}");
        }
        
        if (record.getCompanionRelation() != null) {
            sql.VALUES("companion_relation", "#{companionRelation,jdbcType=VARCHAR}");
        }
        
        if (record.getCompanionPhone() != null) {
            sql.VALUES("companion_phone", "#{companionPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getReason() != null) {
            sql.VALUES("reason", "#{reason,jdbcType=VARCHAR}");
        }
        
        if (record.getOutTime() != null) {
            sql.VALUES("out_time", "#{outTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getReturnTimeForecast() != null) {
            sql.VALUES("return_time_forecast", "#{returnTimeForecast,jdbcType=TIMESTAMP}");
        }
        
        if (record.getRemarks() != null) {
            sql.VALUES("remarks", "#{remarks,jdbcType=VARCHAR}");
        }
        
        if (record.getReturnTimeActual() != null) {
            sql.VALUES("return_time_actual", "#{returnTimeActual,jdbcType=TIMESTAMP}");
        }

        if (record.getApprovalStatus() != null) {
            sql.VALUES("approval_status", "#{ApprovalStatus,jdbcType=CHAR}");
        }

        if (record.getApprover() != null) {
            sql.VALUES("approver",  "#{approver,jdbcType=VARCHAR}");
        }

        if (record.getApprovalTime() != null) {
            sql.VALUES("approval_time","#{ApprovalTime,jdbcType=TIMESTAMP}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(OutgoingRecord record) {
        SQL sql = new SQL();
        sql.UPDATE("outgoing_record");
        
        if (record.getCustomerId() != null) {
            sql.SET("customer_id = #{customerId,jdbcType=INTEGER}");
        }
        
        if (record.getCompanion() != null) {
            sql.SET("companion = #{companion,jdbcType=VARCHAR}");
        }
        
        if (record.getCompanionRelation() != null) {
            sql.SET("companion_relation = #{companionRelation,jdbcType=VARCHAR}");
        }
        
        if (record.getCompanionPhone() != null) {
            sql.SET("companion_phone = #{companionPhone,jdbcType=VARCHAR}");
        }
        
        if (record.getReason() != null) {
            sql.SET("reason = #{reason,jdbcType=VARCHAR}");
        }
        
        if (record.getOutTime() != null) {
            sql.SET("out_time = #{outTime,jdbcType=TIMESTAMP}");
        }
        
        if (record.getReturnTimeForecast() != null) {
            sql.SET("return_time_forecast = #{returnTimeForecast,jdbcType=TIMESTAMP}");
        }
        
        if (record.getRemarks() != null) {
            sql.SET("remarks = #{remarks,jdbcType=VARCHAR}");
        }
        
        if (record.getReturnTimeActual() != null) {
            sql.SET("return_time_actual = #{returnTimeActual,jdbcType=TIMESTAMP}");
        }

        if (record.getApprovalStatus() != null) {
            sql.SET("approval_status = #{approvalStatus,jdbcType=CHAR}");
        }

        if (record.getApprover() != null) {
            sql.SET("approver = #{approver,jdbcType=VARCHAR}");
        }

        if (record.getApprovalTime() != null) {
            sql.SET("approval_time = #{approvalTime,jdbcType=TIMESTAMP}");
        }

        sql.WHERE("id = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
}